package temp;

import jxl.read.biff.BiffException;
import obj.Item;
import seotools.positions.direct.DirectHelper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * User: Vladimir
 * Date: 06.09.12 Time: 12:59
 */
public class ModelsCross {
    public static void main(String[] args) throws BiffException, IOException {
        String[] brands = {"Nokia", "Sony Ericsson", "Motorola"};
        List<Item> items = Item.parseItemsXlsDir("data/extramobi/accum/", brands);
        List<Model> trimModels = new ArrayList<Model>();

        for (Item item : items) {
            for (String model : item.models) {
                String trimModel = DirectHelper.trimModel(model, item.brand);
                Model modelObj = new Model(item.brand, trimModel);
                if (trimModels.contains(modelObj)) {
                    modelObj = trimModels.get(trimModels.indexOf(modelObj));
                    if (!modelObj.brand.equals(item.brand)) {
                        System.out.println(item.brand + " " + model);
                    }
                } else {
                    trimModels.add(modelObj);
                }
            }
        }
    }

    static class Model {
        String brand;
        String model;

        Model(String brand, String model) {
            this.brand = brand;
            this.model = model;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Model model1 = (Model) o;

            if (model != null ? !model.equals(model1.model) : model1.model != null) return false;

            return true;
        }

        @Override
        public int hashCode() {
            return model != null ? model.hashCode() : 0;
        }
    }
}
